﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using System;
using Swift;

public class MainPanel : MonoBehaviour
{
    public EditorManager EMgr;
    public GameObject PlayBtn;

    byte[] tmpSavedInPlay = null;
    bool playing = false;
    public void OnClickPlay()
    {
        playing = !playing;
        PlayBtn.GetComponentInChildren<Text>().text = playing ? "■" : "▶";
        if (playing)
        {
            var w = new WriteBuffer();
            foreach (var u in EMgr.G.AllUnits)
                u.Serialize(w);
            tmpSavedInPlay = w.Data;
        }
        else
        {
            var r = new RingBuffer(tmpSavedInPlay);
            foreach (var u in EMgr.G.AllUnits)
                u.Deserialize(r);
        }

        EMgr.Play(playing);
    }
}
